extends Panel

signal select

func get_weapon_file_list() -> Array:
	var wl : Array = []
	var path := "res://Weapons/"
	var dir := Directory.new()
	if dir.open(path) == OK:
		dir.list_dir_begin()
		var file_name = dir.get_next()
		while file_name != "":
			if not dir.current_is_dir():
				if file_name != ".." and file_name != "." and file_name != "Weapon.tscn":
					if file_name != "WeaponTestChamber.tscn":
						wl.append(file_name)
			file_name = dir.get_next()
	return wl

func get_weapon_list() -> Array:
	var wl : Array = []
	var wnl : Array = get_weapon_file_list()
	for file_name in wnl:
		var path = "res://Weapons/" + file_name
		wl.append(load(path).instance())
	return wl

func _ready():
	for w in get_weapon_list():
		var B = WeaponButton.new()
		B.weapon = w
		B.text = w.weapon_name
		B.icon = w.get_sprite()
		B.expand_icon = true
		$VBoxContainer.add_child(B)
		B.connect("selected", self, "_on_WB_selected")

func _on_WB_selected(w: Weapon):
	emit_signal("select", w)
